<template>
  <view class="cartBox" v-if="cart.length!==0">
    <!-- 商品地址区域 -->
    <my-address></my-address>
    <!-- 商品列表的标题区域 -->
    <view class="cart-title">
      <!-- 左侧图标 -->
      <uni-icons type="shop" size="19"></uni-icons>
      <!-- 右侧文本 -->
      <text class="cart-title-text">购物车</text>
    </view>
    <!-- 商品列表展示区域 -->
    <uni-swipe-action>
      <block v-for="(good,i) in cart" :key="i">
        <!-- 滑动删除组件使用 -->
        <uni-swipe-action-item :right-options="options" @click="deleteGood(good)">
          <my_goods @onchangeCount="editCount" :showNumberBox="true" @radioState='changeRadioState' :good="good"
            :showRadio="true"></my_goods>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
    <!-- <block v-for="(good,i) in cart" :key="i">
  <my_goods @onchangeCount="editCount" :showNumberBox="true" @radioState='changeRadioState' :good="good" :showRadio="true"></my_goods>
 </block> -->
 <my-settle></my-settle>
  </view>
  <view class="empty" v-else>
    <image src="../../static/cart_empty@2x.png" class="img-empty"></image>
    <text class="tip">空空如也~</text>
  </view>
</template>

<script>
  import {
    mapState,
    mapMutations,
  } from 'vuex'
  import cartBadge from '@/mixins/tabbar-badge.js'
  export default {
    mixins: [cartBadge],
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#c00000'
          }
        }]
      }
    },
    computed: {
      ...mapState('m_cart', ['cart']),
    },
    methods: {
      ...mapMutations('m_cart', ['updateRadio', 'updateCount', 'removeGood']),
      // 修改radio的状态
      changeRadioState(good) {
        // console.log(good);
        this.updateRadio(good)
      },
      // 修改单件商品数量
      editCount(good) {
        this.updateCount(good)
        // console.log(good);
      },
      // 删除某商品
      deleteGood(good) {
        // console.log(good);
        this.removeGood(good)
      },
     
    }
  }
</script>

<style lang="less" scoped>
  .cartBox{
   padding-bottom: 50px;
  }
  .cart-title {
    height: 40px;
    display: flex;
    align-items: center;
    padding-left: 5px;
    border-bottom: 1px solid #efefef;

    .cart-title-text {
      font-size: 14px;
      margin-left: 10px;
    }
  }
  .empty{
    display: flex;
    flex-direction:column;
    align-items: center;
    padding-top: 150px;
    .img-empty{
      width: 90px;
      height: 90px;
    }
    .tip{
      font-size: 12px;
      color: gray;
      margin-top: 15px;
    }
  }
</style>
